package com.pay.service;

import com.pay.model.TbCustInfo;
import com.pay.utils.DatabaseHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.crypto.Data;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * tb_cust_info 逻辑处理
 * Created by Administrator on 2017-7-5.
 */
public class CustService {
    private static final Logger logger = LoggerFactory.getLogger(CustService.class);

    /**
     * 获取客户列表
     * @return
     */
//    public List<TbCustInfo> findList(){
//        Connection connection = null;
//        TbCustInfo tbCustInfo = null;
//        List<TbCustInfo> custList = new ArrayList<TbCustInfo>();
//        String querySQL = "select * from tb_cust_info where 1=1";
//        try {
//            connection = DatabaseHelper.getConnection();
//            PreparedStatement statement = connection.prepareStatement(querySQL);
//            ResultSet rs = statement.executeQuery();
//            while (rs.next()){
//                tbCustInfo = new TbCustInfo();
//                tbCustInfo.setId(rs.getLong("id"));
//                tbCustInfo.setCustNo(rs.getString("custNo"));
//                tbCustInfo.setCustName(rs.getString("custName"));
//                tbCustInfo.setEmail(rs.getString("email"));
//                tbCustInfo.setPhoneNo(rs.getString("phoneNo"));
//                tbCustInfo.setRemark(rs.getString("remark"));
//                custList.add(tbCustInfo);
//            }
//            return custList;
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }finally {
//            DatabaseHelper.closeConnection(connection);
//        }
//        return null;
//    }
    public List<TbCustInfo> findList(){
        String querySQL = "select * from tb_cust_info where 1=1";
        return DatabaseHelper.queryEntityList(TbCustInfo.class,querySQL);
    }

    /**
     * 根据ID获取客户信息
     *@return
     */
    public TbCustInfo findCustInfoById(long id){
        String sql = "select * from tb_cust_info where id=?";
        return DatabaseHelper.queryEntity(TbCustInfo.class,sql,id);
    }

    /**
     * 保存客户信息
     * @param fieldMap
     * @return
     */
    public boolean saveCustInfo(Map<String,Object> fieldMap){
        return DatabaseHelper.insertEntity(TbCustInfo.class,fieldMap);
    }

    /**
     * 更新客户信息
     * @Param id,fieldMap
     * @return
     */
    public boolean updateCustInfo(long id,Map<String,Object> fieldMap){
        return DatabaseHelper.updateEntity(TbCustInfo.class,id,fieldMap);
    }

    /**
     * 删除客户信息
     * @param id
     * @return
     */
    public boolean deleteCustInfo(long id){
        return DatabaseHelper.deleteEntity(TbCustInfo.class,id);
    }


}
